﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Xml.Serialization;

namespace ReportGen.Model
{
    /// <summary>
    /// 单元格
    /// </summary>
    [XmlType("C")]
    public class Cell
    {
        #region 属性
        /// <summary>
        /// 列号
        /// </summary>
        [XmlAttribute("c")]
        public int Col { get; set; }

        /// <summary>
        /// 行号
        /// </summary>
        [XmlAttribute("r")]
        public int Row { get; set; }

        /// <summary>
        /// 列合并
        /// </summary>
        [XmlAttribute("cs")]
        public int ColSpan { get; set; }

        /// <summary>
        /// 行合并
        /// </summary>
        [XmlAttribute("s")]
        public int RowSpan { get; set; }
        #endregion

        [XmlElement("O")]
        public CellContent Content { get; set; }
        

    }

    [XmlType("CellElementList")]
    public class CellElementList
    {
        /// <summary>
        /// 单元格
        /// </summary>
        [XmlElement("C")]
        public List<Cell> Cells { get; set; }

    }


    [XmlType("O")]
    public class CellContent
    {
        [XmlIgnore]
        public string ContentCDATA { get; set; }

        [XmlText()]
        public XmlNode[] Content
        {
            get
            {
                var dom = new XmlDocument();
                return new XmlNode[] { dom.CreateCDataSection(this.ContentCDATA) };
            }
            set
            {
                if (value == null)
                {
                    this.ContentCDATA = null;
                    return;
                }
                if (value.Length != 1)
                    throw new InvalidOperationException("Invalid array.");
                var content = value[0];
                if (null == content)
                    throw new InvalidOperationException("Node is null.");
                this.ContentCDATA = content.Value;
            }
        }

    }
}
